#include <windows.h>
#include "CEventPacket.h"

CEventPacket::CEventPacket(unsigned int eventId) {

	this->type		=	0x32;
	this->size		=	0x0A;

	this->numOfParams = 0;

	sprintf(this->m_eventScriptFunction, "none");
	sprintf(this->m_eventScript, "none");

	memset(this->data, 0, 500);
	memset(this->m_param, 0, sizeof(unsigned int)*8);

	this->m_eventId   = eventId;
	this->m_zoneId    = 0;

}

void CEventPacket::createPacket(CChar * schar) {

	if(this->numOfParams > 0) {

		this->type		=	0x34;
		this->size		=	0x1A;

		memcpy(this->data, &schar->m_id, 4);

		for (unsigned int i = 0; i < this->numOfParams; i++) {
			memcpy(this->data+0x04+((i))*4,(unsigned char*)&this->m_param[i],4);
		}
		unsigned short targId = schar->getTargId();
		memcpy(this->data+0x24, &targId, 2);

		this->data[0x2A-4] = (unsigned char(schar->getZone()));
		this->data[0x30-4] = (unsigned char(schar->getZone()));

		memcpy(this->data+0x2c-4, &this->m_eventId, 4);
		this->data[0x2E-4] = (unsigned char(this->numOfParams));

	} else {

		memcpy(this->data, &schar->m_id, 4);
		unsigned short targId = schar->getTargId();
		memcpy(this->data+4, &targId, 2);
		memcpy(this->data+6, &schar->loc.zone, 1);
		memcpy(this->data+8, &this->m_eventId, 4);
		memcpy(this->data+12, &schar->loc.zone, 1);

	}

	if(strcmp(this->m_eventScriptFunction, "none")) {
		memcpy(schar->eventQ.eventScriptFunction, this->m_eventScriptFunction, 255);
	}

	if(strcmp(this->m_eventScript, "none")) {
		memcpy(schar->eventQ.eventScript, this->m_eventScript, 255);
	}

	schar->quePacket(*this);
	schar->inEvent = true;

}
	
CEventPacket::~CEventPacket(void) {

}